package com.magic.ch04_枚举模拟与排序.连号区间数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int n = Integer.parseInt(br.readLine());
        String[] read = br.readLine().split(" ");
        int[] arr = new int[n + 5];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(read[i]);
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            for (int j = i; j < n; j++) {
                min = Math.min(min, arr[j]);
                max = Math.max(max, arr[j]);
                if (max - min == j - i) ans++;
            }
        }
        pw.println(ans);
        br.close();
        pw.flush();
        pw.close();
    }
}
